<?php
require_once('./class/Individu.php');

switch(@$_GET['action']){

    default:
        echo _INDIVIDU_;
    break;

    case "addForm":
        echo Individu::getAddForm();
        break;

    case "doAdd":
        $i = new Individu();
        $i->setNom($_POST['nom']);
        $i->setPrenom($_POST['prenom']);
        $i->addOrModify();
        echo $i->getPrenom()." ".$i->getNom()." added";
        break;

    case "modifyForm":
        $i = Individu::getIndividu($_GET['id']);
        echo $i->getModifyForm();
        break;

    case "doModify":
        $i = new Individu();
        $i->setId($_POST['id_individu']);
        $i->setNom($_POST['nom']);
        $i->setPrenom($_POST['prenom']);
        $i->addOrModify();
        echo "Individu modified";
        break;

    case "list":
        $array = Individu::getAllIndividu();
        $html = '<table class="tablesorter">
						<thead>
							<th>'._ID_INDIVIDU_.'</th>
							<th>'._NOM_INDIVIDU_.'</th>
							<th>'._PRENOM_INDIVIDU_.'</th>
							<th>'._EDIT_.'</th>
							<th>'._DELETE_.'</th>
						</thead><tbody>';
        $i = 0;
        foreach($array as $r){
            $odd = ($i % 2 == 0) ? 'class="odd"' : "";
            $i++;
            $html .= '<tr '.$odd.'>
						<td>'.$r->getIdIndividu().'</td>
						<td> ' .$r->getNom().'</td>
						<td>'.$r->getPrenom().'</td>
						<td><a href="?module=individu&action=modifyForm&id='.$r->getIdIndividu().'">'._EDIT_.'</a></td>
						<td><a href="?module=individu&action=delete&id='.$r->getIdIndividu().'">'._DELETE_.'</a></td>
					</tr>';
        }
        $html .= '</tbody></table>';
        echo $html;
        break;

    case "delete":
        $i = Individu::getIndividu($_GET['id']);
        $i->delete();
        echo $i->getNom().' '.$i->getPrenom().' '. _DELETED;
        break;
}
?>
